package logic

import (
	"context"
	"video-up-manager/models/mysql"

	"video-up-manager/videorpc/internal/svc"
	"video-up-manager/videorpc/videorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type VideoAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewVideoAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VideoAddLogic {
	return &VideoAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *VideoAddLogic) VideoAdd(in *videorpc.VideoAddRequest) (*videorpc.VideoAddResponse, error) {
	// todo: add your logic here and delete this line

	video := mysql.Video{
		UploadUserId:  in.UploadUserId,
		VideoTitle:    in.VideoTitle,
		VideoCategory: in.VideoCategory,
		VideLink:      in.VideLink,
		CoverLink:     in.CoverLink,
		VideoIntro:    in.VideoIntro,
		PlayNum:       in.PlayNum,
		LikeNum:       in.LikeNum,
		CollectNum:    in.CollectNum,
		CommentNum:    in.CommentNum,
		ReleaseTime:   in.ReleaseTime,
		VideoStatus:   in.VideoStatus,
		TopicId:       in.TopicId,
		VideoDuration: in.VideoDuration,
	}

	if err := video.VideoAdd(mysql.DB); err != nil {
		return nil, err
	}

	return &videorpc.VideoAddResponse{
		VideoId: int64(video.ID),
	}, nil
}
